package com.achievo.know.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.StringUtils;

import com.dayatang.domain.BaseEntity;
import com.dayatang.domain.InstanceFactory;

@Entity
@Table(name="RAMS_SYNC_LOG")
public class SyncLog extends BaseEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = -242749969692110416L;
	public static final String ADD = "增加";
	public static final String ERROR = "出错";
	public static final String EDIT = "更新";
	public static final String DELETE = "删除";

	@Override
	public boolean equals(Object arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return 0;
	}
	
	@Column(name="USER_NAME",length = 25)
	private String username;
	@Column(name = "REAL_NAME")
	private String realName;
	@Column(name = "ACTION",length = 25)
	private String action;
	@Column(name = "NOTES",length = 1000)
	private String desc;
	@Column(name = "SYNC_TIME", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date syncTime;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public Date getSyncTime() {
		return syncTime;
	}

	public void setSyncTime(Date syncTime) {
		this.syncTime = syncTime;
	}
	
	private static SyncLogRepository syncLogRepository;

	public static SyncLogRepository getSyncLogRepository() {
		if (syncLogRepository == null) {
			syncLogRepository = InstanceFactory.getInstance(SyncLogRepository.class);
		}
		return syncLogRepository;
	}

	public static SyncLog createLog(User u,String type,String desc) {
		SyncLog sl=new SyncLog();
		sl.setAction(type);
		sl.setDesc(desc);
		if(!ERROR.equals(type)){
			sl.setRealName(u.getRealName());
			sl.setUsername(u.getUsername());
		}
		sl.setSyncTime(new Date());
		return sl;
	}

}
